fix(watch): clear ambient git env so repo detection honors current_dir - #171
Merged
Conversation
is_git_repo/git_worktree_root set current_dir but inherited GIT_DIR/ GIT_WORK_TREE, so when codegraph runs inside a git hook (post-commit/ post-merge/post-checkout invoke 'codegraph sync') git answered repo queries for the hook's repo instead of the queried directory. Route all git invocations through git_command(), which strips the repo-selection env vars so discovery resolves purely from current_dir.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #171 +/- ##
=======================================
Coverage 95.27% 95.27%
=======================================
Files 124 124
Lines 61312 61316 +4
=======================================
+ Hits 58412 58416 +4
Misses 2900 2900
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
is_git_repo/git_worktree_rootsetcurrent_dir(dir)but inherited the ambient git repo-selection env (GIT_DIR,GIT_WORK_TREE, ...). Whencodegraphruns inside a git hook —post-commit/post-merge/post-checkoutinvokecodegraph sync— git exports those vars, so git answered "is THIS dir a repo? / what's its worktree root?" for the hook's repo, ignoring the directory we actually asked about.Root cause
gitprioritizesGIT_DIR/GIT_WORK_TREEovercurrent_dir. Any git invocation that only setscurrent_diris therefore wrong whenever those vars are present in the environment (git hooks, and — incidentally — agit pushpre-push hook running the test suite).Fix
git_command(dir)ingit.rs: builds thegitcommand rooted atdirandenv_removes the 7 repo-selection vars (GIT_DIR,GIT_WORK_TREE,GIT_COMMON_DIR,GIT_INDEX_FILE,GIT_OBJECT_DIRECTORY,GIT_NAMESPACE,GIT_PREFIX), so discovery resolves purely fromcurrent_dir.is_git_repo,git_output,git_worktree_root, and the two testgit_inithelpers through it.Verification
GIT_DIR/GIT_WORK_TREE(repo query flips true↔false).codegraph-watchlib test suite: 86/86 pass (previously 6 failed).cargo test --workspace: green, no regression.cargo clippy --all-targets -D warnings,cargo fmt --check,scripts/guardrail.sh: all pass.--no-verify.